
let tempList = [];
const vue=new Vue({
    el: '#app',
    data: function () {
        return {
            visible: false,
            isCollapse: false,
            opened: false,
            isActive: false,
            dialogVisible: false,
            list: [{
                id: 1,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                stock: 100,
            }, {
                id: 2,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                stock: 100,
            }, {
                id: 3,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                stock: 100,
            }, {
                id: 4,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                stock: 100,
            }, {
                id: 5,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                stock: 100,
            }, {
                id: 6,
                pic: 'https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg',
                name: '首页',
                category:'猫',
                price: 100,
                stock: 100,
            }],
            listLoading: false,
            listQuery: {
                keyword: null,
                pageNum: 1,
                pageSize: 5,
                publishStatus: null,
                verifyStatus: null,
                productSn: null,
                productCategoryId: null,
                brandId: null
            },
            total: null,
            productAttrCate:{
                name:'',
                id:null,
                pic:'',
                descn:'',
              },
        }
    },
    methods: {
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },
        sidebarHide(){
            $(".sidebar-container").addClass("sidebar-hide");
            alert("sidebarHide");
        },
        sidebarOpen(){
            $(".sidebar-container").removeClass("sidebar-hide");
            alert("sidebarOpen");
        },
        toggleSideBar(){
            alert("togglesidebar");
        },
        sideBar(){
            alert("sidebar");
        },
        toggleClick(){
            this.isActive = !this.isActive;
            this.isCollapse=!this.isCollapse;
        },
        handleCommand(command) {
            window.location.href="/home";
        },
        logout(){

        },
        addProductAttrCate() {
            this.dialogVisible = true;
            this.dialogTitle = "添加类型";
          },
        getList() {
            this.list=JSON.parse(JSON.stringify(tempList));
        },
        addProductAttrCate() {
            this.dialogVisible = true;
            this.dialogTitle = "添加类型";
          },
        handleSizeChange(val) {
            this.listQuery.pageNum = 1;
            this.listQuery.pageSize = val;
            this.getList();
          },
          handleCurrentChange(val) {
            this.listQuery.pageNum = val;
            this.getList();
          },
          handleDelete(index, row) {
            this.$confirm('是否要删除该品牌', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              $.ajax({
                url: '/deleteProductAttr?productId='+row.id,
                type: 'get',
                success: function (data) {
                        tempList.splice(index, 1);
                        vue.getList();
                        vue.$message({
                        type: 'success',
                        message: '删除成功!'
                        });


                }
              })
            });
          },
          handleUpdate(index, row) {
            this.dialogVisible = true;
            this.dialogTitle = "编辑类型";
            this.productAttrCate.name = row.name;
            this.productAttrCate.id = row.id;
          },
          handleConfirm(){
            document.getElementById("productAttrCateForm").submit();
          },
    }
})
function createProductAttrCate(data) {
    return request({
      url:'/addProduct',
      method:'post',
      data:data
    })
    console.log(data)
  }
  
function deleteProductAttrCate(id) {
    return request({
      url:'/#'+id,
      method:'get'
    })
  }
  
 function updateProductAttrCate(id,data) {
    return request({
      url:'/#'+id,
      method:'post',
      data:data
    })
  }

function setList(tpList){
    tempList=JSON.parse(JSON.stringify(tpList));
    console.log(tempList);
    vue.getList();
}
